import React, { Component } from 'react'
import { Suspense } from 'react'
import { Route, Switch, Redirect } from 'react-router-dom'
import { RouterItem } from "../type/router.d"
interface IPROPS {
  routes: RouterItem[]
}
export class routerView extends Component<IPROPS> {
  render() {
    const { routes } = this.props
    return (
      <Suspense fallback={<div>加载中</div>}>
        <Switch>
          {
            routes&&routes.map((item, index) => {
              return <Route key={index} path={item.path} render={(props) => {
                return item.to ? <Redirect to={item.to}></Redirect> : <item.component {...props} children={item.children}></item.component>
              }}></Route>
            })
          }
        </Switch>
      </Suspense>
    )
  }
}

export default routerView